//
//  UIBarButtonItem+Custom.m
//  KeepProject
//
//  Created by amos on 16/1/20.
//  Copyright © 2016年 itheima. All rights reserved.
//

#import "UIBarButtonItem+Custom.h"

@implementation UIBarButtonItem (Custom)

+ (instancetype)barButtonItemWith:(NSString*)title imageName:(NSString*)imageName target:(id)target action:(SEL)action
{

    //1.创建 button
    UIButton* button = [[UIButton alloc] init];

    //2.设置图片
    if (imageName) {
        [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    }

    //3.设置 title
    if (title) {
        [button setTitle:title forState:UIControlStateNormal];
        [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];

        button.titleLabel.font = [UIFont systemFontOfSize:14];
    }
    //4.设置点击事件
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];

    [button sizeToFit];

    //4.设置 customView
    //0.创建自身
    UIBarButtonItem* itme = [[UIBarButtonItem alloc] initWithCustomView:button];

    return itme;
}

@end
